#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int n = 0;
	int m = 0;
	int arr[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
	////int arr1[] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
	while (~scanf("%d %d", &n, &m))
	{
		if ((n % 4 == 0 && n % 100 != 0) || (n % 400 == 0))
		{
			if (m == 2)
			{
				printf("%d\n", 29);
			}
			else
			{
				printf("%d\n", arr[m - 1]);
			}
		}
		else
		{
			printf("%d\n", arr[m - 1]);
		}
		////if ((n % 4 == 0 && n % 100 != 0) || (n % 400 == 0))
		////{
		////	printf("%d\n", arr1[m - 1]);
		////}
		////else
		////{
		////	printf("%d\n", arr[m - 1]);
		////}
		//if (m==4|| m == 6 || m == 9 || m == 11)
		//{
		//	printf("%d\n", 30);
		//}
		//else if (m == 2)
		//{
		//	if ((n % 4 == 0 && n % 100 != 0) || (n % 400 == 0))
		//	{
		//		printf("%d\n", 29);
		//	}
		//	else
		//	{
		//		printf("%d\n", 28);
		//	}
		//}
		//else
		//{
		//	printf("%d\n", 31);
		//}

	}
	return 0;
}